package cn.yyh.commons.exception;

import cn.yyh.commons.utils.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 杨永航
 * @version 1.0
 * @Title: GlobalExceptionHandler
 * @Package: com.atguigu.servicebase.exceptionhandler
 * @date 2021/6/17
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(MyException.class)
    @ResponseBody
    public R error(MyException e) {
        e.printStackTrace();
        return R.error().message(e.getMessage()).code(e.getCode());
    }

}
